<?php
	class hotelAvailableClass {
		protected $param = array(
								"apiKey" => null,
								"cid" => null,
								"locale" => null,
								"currencyCode" => null,
								"destinationId" => null,
								"arrivalDate" => null,
								"departureDate" => null,
								"occupancy" => null								
							);
							
		protected $wsdl = "http://api.ean.com/ean-services/ws/hotel/v3?wsdl&apiKey=t9grpd33pwudkegxpdrq6xp5";
		protected $objClient;
		protected $xmlParam;
		protected $soapvar;
		protected $objResponse;
		protected $response;
		protected $hotelAvailable;
		protected $globalResult = array();
		
		protected function setXmlparam(){	
			$this->xmlParam = '<v3:getList> 
								 <HotelListRequest>
									<apiKey>'.$this->param['apiKey'].'</apiKey>
									<cid>'.$this->param['cid'].'</cid>
									<minorRev>9</minorRev> 
									<customerIpAddress></customerIpAddress>
									<customerSessionId></customerSessionId>
									<customerUserAgent></customerUserAgent>
									<locale>'.$this->param['locale'].'</locale>
									<currencyCode>'.$this->param['currencyCode'].'</currencyCode>
									<destinationId>'.$this->param['destinationId'].'</destinationId>
									<numberOfResults>10</numberOfResults>
									<arrivalDate>'.$this->param['arrivalDate'].'</arrivalDate>
									<departureDate>'.$this->param['departureDate'].'</departureDate>
									<RoomGroup>
									   <Room>
										  <numberOfAdults>'.$this->param['occupancy'].'</numberOfAdults>
									   </Room>
									</RoomGroup>
								 </HotelListRequest>
							  </v3:getList>';
		}
		
		protected function getdataParam(){
			$this->objClient = new SoapClient($this->wsdl, array('trace' => true,'exceptions' => 0,'features'=>SOAP_SINGLE_ELEMENT_ARRAYS, 'encoding' => 'UTF-8'));
			$this->setXmlparam();
			$this->soapvar = new SoapVar($this->xmlParam, XSD_ANYXML);
			$this->objResponse = $this->objClient->__soapCall("getList", array($this->soapvar));
		}
	
		protected function setSimpleXml(){
			$this->response = $this->objClient->__getLastResponse();
			$xml = simplexml_load_string(htmlspecialchars_decode($this->response), NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
			$xml->registerXPathNamespace('soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
			$xml->registerXPathNamespace('ns1', 'http://v3.hotel.wsapi.ean.com/');
			$result = $xml->xpath('//ns1:getListResponse');
			$result = $result[0]->HotelListResponse;
			$this->hotelAvailable = $result;
		}
		
		public function setParam($apiKey, $cid, $locale, $currencyCode,$destinationId, $arrivalDate, $departureDate, $occupancy){
			$this->param = array(
								"apiKey" => $apiKey,
								"cid" => $cid,
								"locale" => $locale,
								"currencyCode" => $currencyCode,
								"destinationId" => $destinationId,
								"arrivalDate" => $arrivalDate,
								"departureDate" => $departureDate,
								"occupancy" => $occupancy								
							);
					
			$this->getdataParam();
			$this->setSimpleXml();
		}
		
		public function getHotelAvailable(){
			foreach($this->hotelAvailable->HotelList->HotelSummary as $hotelList){
				
				$this->globalResult[] = (object)array(
										"hotelId" => (string)$hotelList->hotelId,
										"hotelName" => (string)$hotelList->name,
										"hotelAddress" => (string)$hotelList->address1,
										"hotelCity" => (string)$hotelList->city,
										"hotelPostalCode" => (string)$hotelList->postalCode,
										"hotelCountryCode" => (string)$hotelList->countryCode,
										"hotelSupplierType" => (string)$hotelList->supplierType,
										"hotelPropertyCategory" => (string)$hotelList->propertyCategory,
										"hotelRating" => (string)static_function::getStarRating($hotelList->hotelRating),
										"hotelConfidenceRating" => (string)$hotelList->confidenceRating,
										"hotelAmenityMask" => (string)$hotelList->amenityMask,
										"hotelTripAdvisorRating" => (string)$hotelList->tripAdvisorRating,
										"hotelTripAdvisorReviewCount" => (string)$hotelList->tripAdvisorReviewCount,
										"hotelTripAdvisorRatingUrl" => (string)$hotelList->tripAdvisorRatingUrl,
										"hotelLocationDescription" => (string)$hotelList->locationDescription,
										"hotelShortDescription" => (string)str_replace(array("Location. "), array(""), strip_tags($hotelList->shortDescription)),
										"hotelLowRate" => (string)$hotelList->lowRate,
										"hotelRateCurrencyCode" => (string)$hotelList->rateCurrencyCode,
										"hotelLatitude" => (string)$hotelList->latitude,
										"hotelLongitude" => (string)$hotelList->longitude,
										"hotelImage" => (string)"http://images.travelnow.com".str_replace("t.jpg","b.jpg",$hotelList->thumbNailUrl),
										"hotelDeepLink" => (string)$hotelList->deepLink
										
				);
		
			}
			return 	$this->globalResult;
		}
		
	}
	
	//$hotelAvailbable = new hotelAvailableClass();
	//$hotelAvailbable->setParam("t9grpd33pwudkegxpdrq6xp5","55505","en_US","USD","6596BFE0-C9B1-4789-B7D1-9ACA0D4FEFE9","09/04/2013","09/05/2013","2");
?>
<!--<pre><?php //print_r($hotelAvailbable->getHotelAvailable()); ?></pre>-->